home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / html / vendors / adobe / software / ppd / ppd_1.0 / easyinst.ppd next >
Text File  |  1997-06-17  |  13KB  |  608 lines

  1. #!/bin/sh
  2. # Copyright (c) 1994 by Adobe Systems Incorporated.
  3. # Script called immediately after a package is installed.
  4. # $1=Install directory for package.
  5. # $2=Directory original script was run from.
  6. ########################################################
  7.  
  8. ###########################################################################
  9. #
  10. #            BEGIN SUBROUTINES
  11. #
  12. ###########################################################################
  13.  
  14. tell_user_not_enough_space()
  15. {
  16.     ${ECHO} ""
  17.     ${ECHO} ""
  18.     ${ECHO} "There is not enough disk space for installation of the PPD database."
  19.     ${ECHO} "The PPD database requires $total_kbytes kilobytes of disk space"
  20.     ${ECHO} "and you currently have only $disk_kbytes kilobytes of available disk space"
  21.     ${ECHO} "in directory ${PPDDIR}."
  22.     ${ECHO} ""
  23. }
  24.  
  25. #
  26. # status at completion:
  27. #
  28. # 0 - o.k.
  29. # 1 - no directory and could not create
  30. # 2 - inadequate permissions for installation
  31. #
  32.  
  33. validate_ppddir()
  34. {
  35.     # benefit of doubt
  36.     status=$STATUS_OK
  37.  
  38.     # Remove trailing '/' if any
  39.     PPDDIR=`${ECHO} "$PPDDIR" | $SED -e 's/\/$//'`
  40.     if [ ! -d $PPDDIR  ] ; then
  41.         $MKDIR $PPDDIR || { status=$STATUS_DIRERR; return; }
  42.     fi
  43.  
  44.     if [ ! -w $PPDDIR  ] ; then
  45.         status=$STATUS_PERMERR
  46.     fi
  47. }
  48.  
  49. compute_ppddir()
  50. {
  51.     PPDDIR="$DFTPPDDIR"
  52.  
  53.     validate_ppddir
  54.  
  55.     case $status in
  56.         $STATUS_OK)
  57.             ;;
  58.         $STATUS_DIRERR)
  59.             ${ECHO} ""
  60.             ${ECHO} "Could not create directory $PPDDIR."
  61.             ${ECHO} ""
  62.             exit 1
  63.             ;;
  64.         $STATUS_PERMERR)
  65.             ${ECHO} ""
  66.             ${ECHO} "You do not have write permissions for the directory"
  67.             ${ECHO} "$PPDDIR.  Please correct and re-install."
  68.             ${ECHO} ""
  69.             exit 1
  70.             ;;
  71.         *)
  72.             ${ECHO} ""
  73.             ${ECHO} "Internal error. Unable to validate PPD directory."
  74.             eval ${ABORTCMD}
  75.             ;;
  76.     esac
  77.  
  78. }
  79.  
  80. prompt_for_ppddir()
  81. {
  82.     rootdir_loop=0
  83.     while : ; do
  84.         rootdir_loop=`expr $rootdir_loop + 1`
  85.         if [ $rootdir_loop -ge $LOOP_LIMIT ] ; then
  86.             ${ECHO} ""
  87.             ${ECHO} "LOOP_LIMIT exceeded."
  88.             eval ${ABORTCMD}
  89.         fi
  90.         ${ECHO} ""
  91.         ${ECHO} ""
  92.         ${ECHO} "Enter the full pathname for the directory into which the PPD database"
  93.         ${ECHO} $EB"should be installed [press $RETURNKEYNAME for $DFTPPDDIR]: "$EE
  94.         read A
  95.         if [ "$A" = ""  ] ; then
  96.             PPDDIR="$DFTPPDDIR"
  97.         else
  98.             PPDDIR="$A"
  99.         fi
  100.  
  101.         validate_ppddir
  102.     
  103.         case $status in
  104.             $STATUS_OK)
  105.                 break
  106.                 ;;
  107.             $STATUS_DIRERR)
  108.                 ${ECHO} ""
  109.                 ${ECHO} "Could not create directory $PPDDIR."
  110.                 ${ECHO} "Please change permissions as needed or specify another directory or"
  111.                 ${ECHO} "press your interrupt key (often, Ctrl/C) to cancel PPD installation."
  112.                 ;;
  113.             $STATUS_PERMERR)
  114.                 ${ECHO} ""
  115.                 ${ECHO} "You do not have write permissions for the directory"
  116.                 ${ECHO} "$PPDDIR.  Please change permissions as needed or"
  117.                 ${ECHO} "choose another directory or press your interrupt key"
  118.                 ${ECHO} "(often Ctrl/C) to cancel PPD installation."
  119.                 ;;
  120.             *)
  121.                 ${ECHO} ""
  122.                 ${ECHO} "Internal error. Unable to validate PPD directory."
  123.                 eval ${ABORTCMD}
  124.                 ;;
  125.         esac
  126.  
  127.         # if we got here, we have to do it again
  128.         ${ECHO} "Press $RETURNKEYNAME to continue"
  129.         read A
  130.  
  131.     done
  132. }
  133.  
  134. compute_kbytes_avail()
  135. {
  136.     # Get last line of df statement.
  137.     # Prepend X because if the mount point is too long,
  138.     # the df command will result in two lines, with the
  139.     # second line having blanks for the first field.
  140.     lastdfline="X"`$DFCMD $PPDDIR | $LASTLINECMD`
  141.     
  142.     # Determine if there is enough disk space for this install.
  143.     case $KBYTES_AVAIL_FIELD in
  144.         1)
  145.             disk_kbytes=`${ECHO} $lastdfline | awk '{ print $1 }'`
  146.             ;;
  147.         2)
  148.             disk_kbytes=`${ECHO} $lastdfline | awk '{ print $2 }'`
  149.             ;;
  150.         3)
  151.             disk_kbytes=`${ECHO} $lastdfline | awk '{ print $3 }'`
  152.             ;;
  153.         4)
  154.             disk_kbytes=`${ECHO} $lastdfline | awk '{ print $4 }'`
  155.             ;;
  156.         5)
  157.             disk_kbytes=`${ECHO} $lastdfline | awk '{ print $5 }'`
  158.             ;;
  159.         *)
  160.             ${ECHO} ""
  161.             ${ECHO} "Internal error. Unable to determine disk space."
  162.             eval ${ABORTCMD}
  163.             ;;
  164.     esac
  165.  
  166. }
  167.  
  168. ###########################################################################
  169. # Determine and compare versions of source and destination
  170. # PPD files.  Compare major versions.  If they differ, then
  171. # we know the result.  If they are the same, compare minor
  172. # versions.  If they differ, then we know the result.  If
  173. # they are the same, then the versions of the (2) files
  174. # are assumed to be identical.
  175. ###########################################################################
  176.  
  177. compare_versions()
  178. {
  179.     src_version=`cat $srcfile | awk '/\*FileVersion/ { print $2 }'`
  180.     dst_version=`cat $dstfile | awk '/\*FileVersion/ { print $2 }'`
  181.  
  182.     sV=`${ECHO} $src_version | sed 's%\"\([0-9][0-9]*\)\.\([0-9][0-9]*\)\"%\1%'`
  183.     sv=`${ECHO} $src_version | sed 's%\"\([0-9][0-9]*\)\.\([0-9][0-9]*\)\"%\2%'`
  184.     dV=`${ECHO} $dst_version | sed 's%\"\([0-9][0-9]*\)\.\([0-9][0-9]*\)\"%\1%'`
  185.     dv=`${ECHO} $dst_version | sed 's%\"\([0-9][0-9]*\)\.\([0-9][0-9]*\)\"%\2%'`
  186.  
  187.     if [ $sV -lt $dV ]
  188.     then
  189.         status=$LT
  190.         return
  191.     fi
  192.  
  193.     if [ $sV -gt $dV ]
  194.     then
  195.         status=$GT
  196.         return
  197.     fi
  198.  
  199.     if [ $sv -lt $dv ]
  200.     then
  201.         status=$LT
  202.         return
  203.     fi
  204.  
  205.     if [ $sv -gt $dv ]
  206.     then
  207.         status=$GT
  208.         return
  209.     fi
  210.  
  211.     status=$EQ
  212. }
  213.  
  214. diff_em()
  215. {
  216.     ${DIFF} $srcfile $dstfile > /dev/null
  217.  
  218.     status=$?
  219. }
  220.  
  221. copy_hard()
  222. {
  223.     ${CP} $1 $2
  224.     :
  225. }
  226.  
  227. copy_file()
  228. {
  229.     ${ECHO} "Copying $fnam to $dstdir ..."
  230.  
  231.     copy_hard ${srcfile} ${dstdir}/
  232. }
  233.  
  234. copy_safe()
  235. {
  236.     ${ECHO} "Warning:  ${fnam} versions agree, but contents differ."
  237.  
  238.     safe_fnam=${fnam}.Photoshop_3.0
  239.     safe_dstfile=${dstdir}/${safe_fnam}
  240.  
  241.     ${ECHO} "Copying $fnam to ${safe_dstfile} ..."
  242.  
  243.     copy_hard ${srcfile} ${safe_dstfile}
  244. }
  245.  
  246. skip_older_version()
  247. {
  248.     ${ECHO} "Skipping older version of $fnam ..."
  249. }
  250.  
  251. skip_by_request()
  252. {
  253.     ${ECHO} "Skipping $fnam by request ..."
  254. }
  255.  
  256. skip_identical_files()
  257. {
  258.     ${ECHO} "Skipping $fnam, since src/dst files are identical ..."
  259. }
  260.  
  261. search_list()
  262. {
  263.     gotIt=0
  264.  
  265.     for R in $*
  266.     do
  267.         if [ "$AA" = "$R" ]
  268.         then
  269.             gotIt=1
  270.             break
  271.         fi
  272.     done
  273. }
  274.  
  275. parse_response()
  276. {
  277.     AA=`${ECHO} $A | ${TR} '[a-z]' '[A-Z]'`
  278.  
  279.     gotIt=0
  280.  
  281.     search_list "Y" "YES" "YE"
  282.  
  283.     if [ $gotIt = 1 ]
  284.     then
  285.         doIt=1
  286.         doEmAll=0
  287.         return
  288.     fi
  289.  
  290.     search_list "A" "ALL" "AL"
  291.  
  292.     if [ $gotIt = 1 ]
  293.     then
  294.         doIt=1
  295.         doEmAll=1
  296.         return
  297.     fi
  298.  
  299.     search_list "N" "NO"
  300.  
  301.     if [ $gotIt = 1 ]
  302.     then
  303.         doIt=0
  304.         doEmAll=0
  305.         return
  306.     fi
  307. }
  308.  
  309. ask_user_copy_newer()
  310. {
  311.     gotIt=0
  312.  
  313.     while [ $gotIt = 0 ]
  314.     do
  315.         ${ECHO} ""
  316.         ${ECHO} "You currently have an older version of ${fnam}."
  317.         ${ECHO} "OK to replace ${fnam} with a newer version?"
  318.         ${ECHO} "Enter YES, NO, or ALL.  If you enter ALL, then"
  319.         ${ECHO} "all older PPDs will be replaced with newer PPDs"
  320.         ${ECHO} ${EB}"without further prompting [Y/N/A]: "${EE}
  321.         read A
  322.         ${ECHO} ""
  323.         parse_response
  324.     done
  325. }
  326.  
  327. process_ppd_file()
  328. {
  329.     ##############################################
  330.     # If file does not exist in destination
  331.     # directory, then we definitely copy it.
  332.     ##############################################
  333.  
  334.     if [ ! -f $dstfile ]
  335.     then
  336.         copy_file
  337.         return 0
  338.     fi
  339.  
  340.     ##############################################
  341.     # A file with the same name is already there.
  342.     #
  343.     # We compare versions to determine whether or
  344.     # not we need to copy the file.
  345.     #
  346.     ##############################################
  347.  
  348.     compare_versions
  349.  
  350.     case $status in
  351.         $LT)
  352.             skip_older_version
  353.             ;;
  354.         $GT)
  355.             if [ $doEmAll = 1 ]
  356.             then
  357.                 copy_file
  358.             else
  359.                 ask_user_copy_newer
  360.                 if [ $doIt = 1 ]
  361.                 then
  362.                     copy_file
  363.                 else
  364.                     skip_by_request
  365.                 fi
  366.             fi
  367.             ;;
  368.         *)  ##  i.e. EQ
  369.             diff_em
  370.             if [ $status = 0 ]
  371.             then
  372.                 # files are identical
  373.                 skip_identical_files
  374.             else
  375.                 # Uh-oh!  They have the same version,
  376.                 # but they differ in content.
  377.                 #
  378.                 # Issue warning and copy to "safe" place.
  379.                 copy_safe
  380.             fi
  381.             ;;
  382.     esac
  383. }
  384.  
  385. copy_ppd_files()
  386. {
  387.     srcdir=$1
  388.     dstdir=$2
  389.  
  390.     ##############################################
  391.     # Loop through PPD files in source directory.
  392.     # See if we need to copy each PPD file and,
  393.     # if so, copy it.
  394.     ##############################################
  395.  
  396.     for i in $srcdir/*.PPD
  397.     do
  398.  
  399.         fnam=`${BASENAME} $i`
  400.  
  401.         srcfile=${srcdir}/${fnam}
  402.         dstfile=${dstdir}/${fnam}
  403.  
  404.         process_ppd_file
  405.     done
  406. }
  407.  
  408. copy_ppd_database()
  409. {
  410.     ${ECHO} ""
  411.     ${ECHO} $EE"Copying PPD database to $PPDDIR..."$EE
  412.  
  413.     #find $PPD_SOURCE_DIR -name '*.PPD' -print | xargs -i cp \{} $PPDDIR
  414.     copy_ppd_files $PPD_SOURCE_DIR/ppddb $PPDDIR
  415.  
  416.     cp $PPD_SOURCE_DIR/readme.ppd $PPD_SOURCE_DIR/ppddb/README $PPD_SOURCE_DIR/ppddb/Filename.MAP $PPDDIR
  417. }
  418.  
  419. ###########################################################################
  420. #
  421. #            BEGIN RUNNABLE CODE
  422. #
  423. ###########################################################################
  424.  
  425. PPD_KBYTES="8462"
  426. ECHO=echo
  427.  
  428. # return codes for directory validation
  429. STATUS_OK=0
  430. STATUS_DIRERR=1
  431. STATUS_PERMERR=2
  432.  
  433. #return codes for version comparison
  434. LT=-1
  435. EQ=0
  436. GT=1
  437.  
  438. #some control variables for copying ppd files
  439. doEmAll=0
  440. doIt=0
  441.  
  442. LOOP_LIMIT=25
  443. LASTLINECMD="tail -1"
  444. ABORTCMD='${ECHO} ""; ${ECHO} "Canceling PPD installation."; ${ECHO} ""; exit 0'
  445. trap 'eval ${ABORTCMD}' 2
  446. EB="-n "
  447. EE=""
  448. if [ -x /bin/uname ]
  449. then
  450.     osname=`/bin/uname -s`
  451.         # 64 bit IRIX6 returns IRIX64 for uname -s
  452.         firstfour=`${ECHO} "$osname" | sed -e 's/^\(....\).*$/\1/g'`
  453.         if [ "$firstfour" = "IRIX" ] ; then
  454.                 osname="IRIX"
  455.         fi
  456.  
  457.     osversion=`/bin/uname -r`
  458.     check=`${ECHO} "$osversion" | egrep '^[0-9]\.[0-9]*'`
  459.     if [ "$check" != "" ]; then
  460.         osmajor=`${ECHO} "$osversion" | sed -e 's/^\([0-9][0-9]*\).*/\1/'`
  461.     fi
  462. fi
  463. if [ $osname = "SunOS" ] ; then
  464.     STDBINDIR="/usr/bin"
  465.     RETURNKEYNAME="Return"
  466.     if [ $osmajor -ge 5 ] ; then
  467.         # For echo without newline under Sys V, set EB and EE variables
  468.         EB=""
  469.         EE="\c"
  470.         PATH=/usr/sbin:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/usr/sbin:/etc:/usr/etc
  471.         DFCMD="$STDBINDIR/df -k"
  472.         DUCMD="$STDBINDIR/du -sk"
  473.         WHOAMI=`$STDBINDIR/id | $STDBINDIR/sed 's/^[^(]*.\([^)]*\).*/\1/'`
  474.     else
  475.         PATH=/usr/ucb:/usr/bin:/bin:/usr/bin/X11:/usr/openwin/bin:/sbin:/etc:/usr/etc
  476.         DFCMD="$STDBINDIR/df"
  477.         DUCMD="$STDBINDIR/du -s"
  478.         WHOAMI=`/usr/ucb/whoami`
  479.     fi
  480.     KBYTES_AVAIL_FIELD=4
  481. elif [ $osname = "IRIX" ] ; then
  482.     STDBINDIR="/usr/bin"
  483.     RETURNKEYNAME="Enter"
  484.     # For echo without newline under Sys V, set EB and EE variables
  485.     EB=""
  486.     EE="\c"
  487.     PATH=/usr/sbin:/sbin:/usr/bin:/bin:/usr/bsd:/usr/bin/X11:/usr/openwin/bin:/etc:/usr/etc
  488.     DFCMD="$STDBINDIR/df -k"
  489.     DUCMD="$STDBINDIR/du -sk"
  490.     KBYTES_AVAIL_FIELD=5
  491.     WHOAMI=`$STDBINDIR/id | $STDBINDIR/sed 's/^[^(]*.\([^)]*\).*/\1/'`
  492. fi
  493.  
  494. BASENAME="$STDBINDIR/basename"
  495. CP="$STDBINDIR/cp"
  496. DIFF="$STDBINDIR/diff"
  497. ECHO="$STDBINDIR/echo"
  498. MKDIR="$STDBINDIR/mkdir -p"
  499. SED="$STDBINDIR/sed"
  500.  
  501. # If there is a third command line parameter, then assume
  502. # that this script was invoked as part of an Adobe product installation.
  503. # Otherwise, assume this script is run standalone.
  504. STANDALONE=0
  505. DFTPPDDIR=`dirname $1`/PPD
  506. if [ "$3" != "" ] ; then
  507.     PPD_SOURCE_DIR="$3/../ppd"
  508. elif [  "$2" != "" ] ; then
  509.     PPD_SOURCE_DIR="$2/../ppd"
  510. elif [ $# -lt 2 ] ; then
  511.     STANDALONE=1
  512.     PPD_SOURCE_DIR="$1"
  513.     DFTPPDDIR=/usr/adobe/PPD
  514. fi
  515.  
  516. if [ -z "$PPD_SOURCE_DIR" -o ! -d "$PPD_SOURCE_DIR" ] ; then
  517.     ${ECHO} ""
  518.     ${ECHO} "PPD post installation script failure."
  519.     exit 0
  520. fi
  521.  
  522. if [ "$WHOAMI" != root ] ; then
  523.     ${ECHO} ""
  524.     ${ECHO} "Warning: you are not logged in as root. You usually need to be"
  525.     ${ECHO} "superuser/root have sufficient permissions to install PPDs."
  526.     ${ECHO} "Press $RETURNKEYNAME to continue or your interrupt key (often, Ctrl/C)"
  527.     ${ECHO} "to cancel PPD installation."
  528.     read A
  529. fi
  530.  
  531. # Always install PPDs, but only prompt for directory when
  532. # doing "difficultinst" (as opposed to easyinst :-).
  533. doing_easyinst=1
  534.  
  535. if [ "$doing_easyinst" = 1 ] ; then
  536.     compute_ppddir
  537.     compute_kbytes_avail
  538.     total_kbytes="$PPD_KBYTES"
  539.  
  540.     if [ $total_kbytes -ge $disk_kbytes ] ; then
  541.         tell_user_not_enough_space
  542.         # just bail
  543.         exit 1
  544.     fi
  545. else
  546.     # Loop around prompts to handle case where user had insufficient
  547.     # space or permissions the first time through.
  548.     while : ; do
  549.         if [ "$PPDDIR" != "" ] ; then
  550.             DFTPPDDIR="$PPDDIR"
  551.         fi
  552.  
  553.         if [ $STANDALONE = 0 ] ; then
  554.             PPDDIR="$DFTPPDDIR"
  555.             validate_ppddir
  556.  
  557.             case $status in
  558.                 $STATUS_OK)
  559.                     ;;
  560.                 $STATUS_DIRERR)
  561.                     ${ECHO} ""
  562.                     ${ECHO} "Could not create directory $PPDDIR."
  563.                     ${ECHO} ""
  564.                     exit 1
  565.                     ;;
  566.                 $STATUS_PERMERR)
  567.                     ${ECHO} ""
  568.                     ${ECHO} "You do not have write permissions for the directory"
  569.                     ${ECHO} "$PPDDIR.  Please correct and re-install."
  570.                     ${ECHO} ""
  571.                     exit 1
  572.                     ;;
  573.                 *)
  574.                     ${ECHO} ""
  575.                     ${ECHO} "Internal error. Unable to validate PPD directory."
  576.                     eval ${ABORTCMD}
  577.                     ;;
  578.             esac
  579.         else
  580.             # Ask user where to install PPD database
  581.             prompt_for_ppddir
  582.         fi
  583.  
  584.         # Compute kilobytes available
  585.         compute_kbytes_avail
  586.  
  587.         total_kbytes="$PPD_KBYTES"
  588.  
  589.         if [ $total_kbytes -ge $disk_kbytes ] ; then
  590.  
  591.             tell_user_not_enough_space
  592.  
  593.             ${ECHO} "Please free up space or choose a different directory or press"
  594.             ${ECHO} "your interrupt key (often, Ctrl/C) to cancel PPD installation."
  595.             ${ECHO} "Press $RETURNKEYNAME to continue"
  596.             read A
  597.         else
  598.             break
  599.         fi
  600.     done
  601. fi
  602.  
  603. copy_ppd_database
  604.  
  605. ${ECHO} done
  606.  
  607. exit 0
  608.